package cn.iocoder.boot.MLlib;

import cn.iocoder.boot.MLlib.DataProcessingService;
import cn.iocoder.boot.MLlib.ModelTrainingService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;

@RestController
//Spring MVC 控制器，提供 RESTful API 来触发数据处理和模型预测。
@RequestMapping("/api/data")
public class DataController {

    @Autowired
    private DataProcessingService dataProcessingService;

    @Autowired
    private ModelTrainingService modelTrainingService;

    @GetMapping("/process")
    public String processData() {
        dataProcessingService.processDataStream();
        return "Data processing started.";
    }

    @GetMapping("/train")
    public String trainModel(@RequestParam String trainingDataPath, @RequestParam String modelSavePath) throws IOException {
        modelTrainingService.trainAndSaveModel(trainingDataPath, modelSavePath);
        return "Model training started.";
    }
}